﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;

namespace Classes
{
     [DataContract]
     //[KnownType(typeof(City))]
     //[KnownType(typeof(Flight))]
    public class Connection
    {
         
        IList<Flight> flights;
         
        IList<City> cities;
        
        City departureCity;

         
        City destinationCity;

       
        int totalTime;
       
        int totalPrice;
         
        int numberOfFlightChange;
     
        int noOfseatsLeft;
       
        int noOfSeatsReservedByCustomer;

      
        DateTime departureTime;
        
        DateTime arrivalTime;
     
        string currency;
      
        int id;
        
       
        public Connection() // the same as flight with fields in constructor
        {
            flights = new List<Flight>();
            cities = new List<City>();
            //foreach (Flight item in flights)
            //{
            //    totalPrice = totalPrice + item.PriceOfTheOneSeat;
            //}
            
            //sequenceOfParentCities = new List<City>();
        }



         
        public int NoOfSeatsReservedByCustomer1
        {
            get { return noOfSeatsReservedByCustomer; }
            set { noOfSeatsReservedByCustomer = value; }
        }
       
        public string Currency
        {
            get { return currency; }
            set { currency = value; }
        }

         [DataMember]
        public DateTime ArrivalTime
        {
            get { return arrivalTime; }
            set { arrivalTime = value; }
        }

         [DataMember]
        public DateTime DepartureTime
        {
            get { return departureTime; }
            set { departureTime = value; }
        }
                
        public int NoOfSeatsReservedByCustomer
        {
            get { return NoOfSeatsReservedByCustomer1; }
            set { NoOfSeatsReservedByCustomer1 = value; }
        }
                  
        public int NoOfseatsLeft
        {
            get { return noOfseatsLeft; }
            set { noOfseatsLeft = value; }
        }

         [DataMember]
        public int NumberOfFlightChange
        {
            get { return numberOfFlightChange; }
            set { numberOfFlightChange = value; }
        }
         [DataMember]
        public int TotalPrice
        {
            get { return totalPrice; }
            set { totalPrice = value; }
        }
               

        public int TotalTime
        {
            get { return totalTime; }
            set { totalTime = value; }
        }

       [DataMember]
        public City DestinationCity
        {
            get { return destinationCity; }
            set { destinationCity = value; }
        }

         [DataMember]
        public City DepartureCity
        {
            get { return departureCity; }
            set { departureCity = value; }
        }
        
        public IList<City> Cities
        {
            get { return cities; }
            set { cities = value; }
        }
                 
         [DataMember]
        public IList<Flight> Flights
        {
            get { return flights; }
            set { flights = value; }
        }
        
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        
        public IList<Flight> FlightList()
        {
            return Flights;
        }
         
        public void SetCityList(IList<City> visited)
        {
            Cities = visited;
        }
         
        public void SetFlightList(IList<Flight> value)
        {
            Flights = value;
        }
         
        public void RemoveFlight(Flight flight)
        {
            Flights.Remove(flight);
        }
         
        public void AddFlight(Flight flight)
        {
            Flights.Add(flight);
        }
         
        public IList<Flight> MakeFlightsOfCities(IList<City> list)
        {
            //foreach (City c in list)
            //{
            //    Console.WriteLine(c.Name);
            //    Console.WriteLine(" ");
            //}
            //Console.WriteLine();
            //return null;
            for (int i = 0; i < list.Count() - 1; i++)
            {
                City c = list[i];
                City x = list[i + 1];
                Flight y = c.Flights().First(z => z.To == x);
                
               
                Flights.Add(y);
            }
            SetFlightList(Flights);
            Console.WriteLine();
            
            return Flights;
        }
         
        public void Print()
        {
            foreach(Flight f in Flights)
            {
                Console.WriteLine(f.From.Name + " ---> " + f.To.Name);

            }
        }
        
        public IList<City> CitiesList()
        {
            return Cities;
        }

    }
}
